package http

import (
	"net/http"
	"net/url"
	"time"
)

type Options struct {
	Params   url.Values        `json:"params,omitempty"`
	Timeout  time.Duration     `json:"timeout,omitempty"`
	Headers  map[string]string `json:"headers,omitempty"`
	IsDebug  bool              `json:"is_debug,omitempty"`
	Body     []byte            `json:"body,omitempty"`
	RawRes   []byte            `json:"raw_res,omitempty"`
	Response *http.Response    `json:"response,omitempty"`
	Proxy    string            `json:"proxy,omitempty"` // "http://username:password@inproxy.sjtu.edu.cn:8000" or url.Parse("http://inproxy.sjtu.edu.cn:8000") or socks5 10.0.0.1:2388
}

func NewOptioins() *Options {
	return &Options{
		Params:  url.Values{},
		Headers: make(map[string]string),
	}
}

func (o *Options) SetTimeout(t time.Duration) *Options {
	o.Timeout = t
	return o
}

func (o *Options) SetParam(key, value string) *Options {
	o.Params.Set(key, value)
	return o
}

func (o *Options) SetHeader(key, value string) *Options {
	o.Headers[key] = value
	return o
}

func (o *Options) SetDebug(debug bool) *Options {
	o.IsDebug = debug
	return o
}

func (o *Options) SetBody(body []byte) *Options {
	o.Body = body
	return o
}

func (o *Options) SetRawRes(res []byte) *Options {
	o.RawRes = res
	return o
}

func (o *Options) SetResponse(res *http.Response) *Options {
	o.Response = res
	return o
}

func (o *Options) SetProxy(proxy string) *Options {
	o.Proxy = proxy
	return o
}
